package com.x.bff.app.factory.customer;

import com.x.bff.app.factory.cms.ContentFactoryImpl;
import com.x.bff.app.model.vo.cms.ItemToggleBothRelationVO;
import com.x.bff.app.model.vo.customer.*;
import com.x.bff.app.model.vo.directory.*;
import com.x.bff.app.service.cms.ContentService;
import com.x.bff.app.service.customer.DirectoryService;
import com.x.core.utils.BeanUtil;
import com.x.core.utils.CompareUtils;
import com.x.provider.api.common.enums.ItemTypeEnum;
import com.x.provider.api.customer.enums.*;
import com.x.provider.api.customer.model.dto.customer.*;
import com.x.provider.api.customer.service.CustomerRpcService;
import com.x.provider.api.general.enums.CustomerStarRelationEnum;
import com.x.provider.api.general.enums.ItemToggleRelationEnum;
import com.x.provider.api.general.enums.ItemToggleRelationTypeEnum;
import com.x.provider.api.general.model.dto.cms.*;
import com.x.provider.api.general.service.CmsRpcService;
import com.x.provider.api.oss.service.OssRpcService;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.management.Attribute;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class CustomerFactoryImpl implements CustomerFactory{

    private final CustomerRpcService customerRpcService;
    private final OssRpcService ossRpcService;
    private final CmsRpcService cmsRpcService;
    private final DirectoryService directoryService;
    private final ContentService contentService;

    public CustomerFactoryImpl(CustomerRpcService customerRpcService,
                               OssRpcService ossRpcService,
                               CmsRpcService cmsRpcService,
                               DirectoryService directoryService,
                               ContentService contentService){
        this.customerRpcService = customerRpcService;
        this.ossRpcService = ossRpcService;
        this.cmsRpcService = cmsRpcService;
        this.directoryService = directoryService;
        this.contentService = contentService;
    }

    @Override
    public CustomerVO prepare(Long customerId, Long sessionCustomerId) {
        CustomerDTO customerDTO = customerRpcService.listCustomer(CustomerListReqDTO.builder()
                .customerIds(Arrays.asList(customerId))
                .sessionCustomerId(sessionCustomerId)
                .customerOptions(Arrays.asList(CustomerOptions.CUSTOMER.name(), CustomerOptions.CUSTOMER_RESUME.name(), CustomerOptions.CUSTOMER_STAT.name(), CustomerOptions.VERIFICATION.name()
                        , CustomerOptions.CUSTOMER_RESUME_PREFERENCE.name(), CustomerOptions.CUSTOMER_RESOURCE.name()))
                .build()).getData().get(customerId);

        ItemStatisticDTO itemStatisticDTO = cmsRpcService.listStatMap(ItemStatListReqDTO.builder().idList(Arrays.asList(customerId)).itemType(ItemTypeEnum.CUSTOMER.getValue())
                .metricList(Arrays.asList()).build()).getData().get(customerId);

        CustomerResumeDTO customerResumeDTO = customerDTO.getCustomerResumeList().get(0);
        List<String> ossKey = new ArrayList<>(2);
        ossKey.add(customerResumeDTO.getAvatarId());
        if (!StringUtils.isEmpty(customerResumeDTO.getAvatarIdReview())){
            ossKey.add(customerResumeDTO.getAvatarIdReview());
        }
        Map<String, String> urlMap = ossRpcService.listObjectBrowseUrl(ossKey).getData();

        Map<String, AttributeVO> attributeMap = directoryService.listAttribute(AttributeListReqVO.builder().build());
        Set<Integer> regionIdLit = listRegionIdLit(customerDTO.getCustomerResumeList());
        Map<Integer, RegionVO> regionMap = regionIdLit.isEmpty() ? new HashMap<>() : directoryService.listRegion(RegionListReqVO.builder().idList(new ArrayList<>(regionIdLit)).build()).stream().collect(Collectors.toMap(item -> item.getId(), item -> item));

        Map<Integer, Integer> contentTotalMap = cmsRpcService.getMyContentTotal(ContentMyTotalReqDTO.builder().customerId(customerId).itemType(List.of(ItemTypeEnum.ALBUM.getValue()))
                .sessionCustomerId(sessionCustomerId).build()).getData();
        Map<Long, Integer> starRelationMap = sessionCustomerId == null ? new HashMap<>() : cmsRpcService.listStarRelation(StarListReqDTO.builder()
                .itemIdList(Arrays.asList(customerId)).itemType(ItemTypeEnum.CUSTOMER.getValue()).starCustomerId(sessionCustomerId).build()).getData();

        CustomerVO result = prepare(CustomerPrepareDTO.builder().customerResumeDTO(customerResumeDTO).urlMap(urlMap).customerDTO(customerDTO).attributeMap(attributeMap)
                .contentTotalMap(contentTotalMap).itemStatisticDTO(itemStatisticDTO).regionMap(regionMap).build());
        prepareResourceSummary(customerId, result);
        return result;
    }

    private void prepareResourceSummary(Long customerId, CustomerVO dest){
        Long resumeReadCount = customerRpcService.operateCustomerResource(CustomerResourceOperReqDTO.builder()
                .operBizSceneId(CustomerResourceOperBizScene.CustomerResourceAddBizSceneEnum.ADD_RESUME_READ_COUNT_4_DAILY.getId()).customerId(customerId).build()).getData();
        Long imSendCount = customerRpcService.operateCustomerResource(CustomerResourceOperReqDTO.builder()
                .operBizSceneId(CustomerResourceOperBizScene.CustomerResourceAddBizSceneEnum.ADD_IM_SEND_COUNT_4_DAILY.getId()).customerId(customerId).build()).getData();
        if (dest.getCustomerResourceSummary() == null){
            dest.setCustomerResourceSummary(new CustomerResourceSummaryVO());
        }
        dest.getCustomerResourceSummary().setImSendCount(imSendCount);
        dest.getCustomerResourceSummary().setResumeReadCount(resumeReadCount);
    }

    @Override
    public List<CustomerVO> prepare(List<Long> customerIdList, Long sessionCustomerId) {
        final Map<Long, CustomerDTO> customerMap = customerRpcService.listCustomer(CustomerListReqDTO.builder()
                .customerIds(customerIdList)
                .sessionCustomerId(sessionCustomerId)
                .customerOptions(Arrays.asList(CustomerOptions.CUSTOMER.name(), CustomerOptions.CUSTOMER_RESUME.name(), CustomerOptions.CUSTOMER_STAT.name(),
                        CustomerOptions.CUSTOMER_RELATION.name())).build()).getData();

        final Map<Long, ItemStatisticDTO> statisticMap = cmsRpcService.listStatMap(ItemStatListReqDTO.builder().idList(customerIdList).itemType(ItemTypeEnum.CUSTOMER.getValue())
                .metricList(Arrays.asList()).build()).getData();

        Map<Long, ItemToggleRelationDTO> fromStarRelation = CompareUtils.gtZero(sessionCustomerId) ? contentService.listCustomerStarRelation(sessionCustomerId, null,
                 null, customerIdList).stream().collect(Collectors.toMap(item -> item.getToItemId(), item -> item)) : new HashMap<>();

        List<String> ossKey = new ArrayList<>(customerIdList.size());
        customerMap.entrySet().stream().forEach(item -> {
            if (!CollectionUtils.isEmpty(item.getValue().getCustomerResumeList())){
                item.getValue().getCustomerResumeList().stream().forEach(opt -> {
                    ossKey.add(opt.getAvatarId());
                });
            }
        });
        Map<String, String> urlMap = ossRpcService.listObjectBrowseUrl(ossKey).getData();

        Map<String, AttributeVO> attributeMap = directoryService.listAttribute(AttributeListReqVO.builder().build());
        Set<Integer> regionIdLit = new HashSet<>();
        customerMap.values().stream().forEach(item ->{
            regionIdLit.addAll(listRegionIdLit(item.getCustomerResumeList()));
        });
        Map<Integer, RegionVO> regionMap = regionIdLit.isEmpty() ? new HashMap<>() : directoryService.listRegion(RegionListReqVO.builder().idList(new ArrayList<>(regionIdLit)).build()).stream().collect(Collectors.toMap(item -> item.getId(), item -> item));
        List<CustomerVO> result = new ArrayList<>(customerIdList.size());
        customerIdList.stream().forEach(item ->{
            final CustomerDTO customerDTO = customerMap.get(item);
            if (customerDTO == null){
                return;
            }
            CustomerPrepareDTO customerPrepareDTO = CustomerPrepareDTO.builder()
                    .customerDTO(customerDTO).itemStatisticDTO(statisticMap.get(item)).customerResumeDTO(customerDTO.getCustomerResumeList().get(0))
                    .urlMap(urlMap).attributeMap(attributeMap).contentTotalMap(null).fromStarRelation(fromStarRelation).regionMap(regionMap)
                    .build();
            CustomerVO customerVO = prepare(customerPrepareDTO);
            result.add(customerVO);
        });
        return result;
    }

    @Override
    public List<CustomerSimpleVO> prepareCustomerSimple(List<CustomerSimpleDTO> src) {
        if (CollectionUtils.isEmpty(src)){
            return new ArrayList<>();
        }
        List<CustomerSimpleVO> result = new ArrayList<>(src.size());
        src.stream().forEach(item -> {
            CustomerSimpleVO customerSimpleVO = BeanUtil.prepare(item, CustomerSimpleVO.class);
            if (item.getStatistic() != null) {
                customerSimpleVO.setStatistic(BeanUtil.prepare(item.getStatistic(), CustomerStatVO.class));
            }
            result.add(customerSimpleVO);
        });
        return result;
    }

    @Override
    public List<CustomerSimpleVO> prepareCustomerRelation(List<CustomerRelationDTO> src, Integer relation, Long sessionCustomerId) {
        List<Long> customerIdList = CustomerRelationEnum.FOLLOW.getValue() == relation ? src.stream().map(item -> item.getToCustomerId()).collect(Collectors.toList()) :
                src.stream().map(item -> item.getFromCustomerId()).collect(Collectors.toList());
        Map<Long, CustomerSimpleDTO> simpleCustomerMap = customerRpcService.listSimpleCustomer(CustomerListReqDTO.builder().customerIds(customerIdList).sessionCustomerId(sessionCustomerId)
                .customerOptions(List.of(CustomerOptions.CUSTOMER.name(), CustomerOptions.CUSTOMER_RESUME.name(), CustomerOptions.CUSTOMER_RELATION.name(), CustomerOptions.CUSTOMER_STAT.name()))
                .build()).getData();
        return prepareCustomerSimple(simpleCustomerMap.values().stream().collect(Collectors.toList()));
    }

    @Override
    public List<CustomerSimpleVO> prepareCustomerStarRelation(List<ItemToggleRelationDTO> src) {
        if (CollectionUtils.isEmpty(src)){
            return new ArrayList<>();
        }
        List<Long> customerIdList = src.stream().map(item -> item.getToItemId()).collect(Collectors.toList());
        Map<Long, CustomerSimpleDTO> simpleCustomerMap = customerRpcService.listSimpleCustomer(CustomerListReqDTO.builder().customerIds(customerIdList).sessionCustomerId(0L)
                .customerOptions(List.of(CustomerOptions.CUSTOMER.name(), CustomerOptions.CUSTOMER_RESUME.name()))
                .build()).getData();
        List<CustomerSimpleVO> result = prepareCustomerSimple(simpleCustomerMap.values().stream().collect(Collectors.toList()));
        Map<Long, ItemToggleRelationDTO> relationMap = src.stream().collect(Collectors.toMap(item -> item.getToItemId(), item -> item));
        result.stream().forEach(item ->{
            ItemToggleRelationDTO relation = relationMap.get(item.getId());
            item.setStarRelation(prepare(relationMap.get(item.getId())));
        });
        return result;
    }

    private ItemToggleBothRelationVO prepare(ItemToggleRelationDTO src){
        if (src == null){
            return new ItemToggleBothRelationVO();
        }
        return BeanUtil.prepare(src, ItemToggleBothRelationVO.class);
    }
    private void prepareCustomerResource(CustomerVO dest, List<CustomerResourceDTO> src){
        if (CollectionUtils.isEmpty(src)){
            return;
        }
        dest.setCustomerResourceList(BeanUtil.prepare(src, CustomerResourceVO.class));
        CustomerResourceSummaryVO resourceSummary = new CustomerResourceSummaryVO();
        src.stream().collect(Collectors.groupingBy(item -> item.getResourceId())).entrySet().forEach(item -> {
            if (item.getKey().equals(CustomerResourceDefEnum.RESUME_READ_COUNT.getValue())){
                resourceSummary.setResumeReadCount(item.getValue().stream().mapToLong(i -> i.getCount()).sum());
            }
            if (item.getKey().equals(CustomerResourceDefEnum.IM_SEND_COUNT.getValue())){
                resourceSummary.setResumeReadCount(item.getValue().stream().mapToLong(i -> i.getCount()).sum());
            }
        });
        dest.setCustomerResourceSummary(resourceSummary);
    }

    private void prepareStar(CustomerVO dest, ItemToggleRelationDTO relation){
        dest.setStarRelation(ContentFactoryImpl.prepareFromRelation(null, relation));
    }

    private CustomerVO prepare(CustomerPrepareDTO customerPrepareDTO) {
        CustomerVO result = prepare(customerPrepareDTO.getCustomerDTO(), null);
        result.setCustomerResumePreference(BeanUtil.prepare(customerPrepareDTO.getCustomerDTO().getCustomerResumePreference(), CustomerResumePreferenceVO.class));
        CustomerResumeVO customerResumeVO = prepareCustomerResume(customerPrepareDTO, result);
        prepareAttribute(customerResumeVO.getGender(), result.getCustomerResumePreference(), customerPrepareDTO.getAttributeMap());
        prepareRegion(result.getCustomerResumePreference(), customerPrepareDTO.getRegionMap());
        result.setCustomerResume(customerResumeVO);
        prepareCustomerStat(customerPrepareDTO.getCustomerDTO(), customerPrepareDTO.getItemStatisticDTO(), result);
        prepareContentTotal(result.getCustomerStat(), customerPrepareDTO.getContentTotalMap());
        if (customerPrepareDTO.getFromStarRelation() != null) {
            prepareStar(result, customerPrepareDTO.getFromStarRelation().get(customerPrepareDTO.getCustomerDTO().getId()));
        }
        prepareCustomerResource(result, customerPrepareDTO.getCustomerDTO().getCustomerResourceList());
        prepareCustomerVerification(customerPrepareDTO, result);
        return result;
    }

    private void prepareCustomerVerification(CustomerPrepareDTO src, CustomerVO dest){
        dest.setCustomerVerificationList(BeanUtil.prepare(src.getCustomerDTO().getVerificationList(), CustomerVerificationVO.class));
    }

    private CustomerResumeVO prepareCustomerResume(CustomerPrepareDTO customerPrepareDTO, CustomerVO result) {
        CustomerResumeVO customerResumeVO = BeanUtil.prepare(customerPrepareDTO.getCustomerResumeDTO(), CustomerResumeVO.class);
        result.setCustomerResume(customerResumeVO);
        prepareAttribute(customerResumeVO, customerPrepareDTO.getAttributeMap());
        prepareUrl(customerResumeVO, customerPrepareDTO.getUrlMap());
        prepareRegion(customerResumeVO, customerPrepareDTO.getRegionMap());
        return customerResumeVO;
    }

    private CustomerVO prepare(CustomerDTO src, CustomerVO dest){
        if (dest == null){
            dest = new CustomerVO();
        }
        dest.setId(src.getId());
        dest.setUserName(src.getUserName());
        dest.setCustomerRelation(src.getCustomerRelation());
        return dest;
    }

    private void prepareCustomerStat(CustomerDTO customerDTO, ItemStatisticDTO itemStatisticDTO, CustomerVO customerHomePageVO) {
        customerHomePageVO.setCustomerStat(new CustomerStatVO());
        prepareCustomerStat(customerHomePageVO.getCustomerStat(), customerDTO.getStatistic());
        prepareItemStat(customerHomePageVO.getCustomerStat(), itemStatisticDTO);
    }
    private void prepareContentTotal(CustomerStatVO customerStatVO, Map<Integer, Integer> contentTotalMap){
        if (contentTotalMap == null){
            return;
        }
        customerStatVO.setAlbumCount(contentTotalMap.getOrDefault(ItemTypeEnum.ALBUM.getValue(), 0).longValue());
    }

    private void prepareCustomerStat(CustomerStatVO dest, CustomerStatDTO customerStatDTO){
        if (customerStatDTO == null){
            return;
        }
        dest.setFansCount(customerStatDTO.getFansCount());
        dest.setFollowCount(customerStatDTO.getFollowCount());
    }

    private void prepareItemStat(CustomerStatVO dest, ItemStatisticDTO itemStatisticDTO){
        if (itemStatisticDTO == null){
            return;
        }
        dest.setStarCount(itemStatisticDTO.getStarCount());
        dest.setMyStarCount(itemStatisticDTO.getMyStarCount());
    }

    private void prepareUrl(CustomerResumeVO dest, Map<String, String> urlMap){
        dest.setAvatarUrl(urlMap.get(dest.getAvatarId()));
        if (!StringUtils.isEmpty(dest.getAvatarIdReview())){
            dest.setAvatarIdUrlReview(urlMap.get(dest.getAvatarIdReview()));
        }
    }

    private void prepareRegion(CustomerResumeVO dest, Map<Integer, RegionVO> regionMap){
        if (dest.getRegionIdLevel1() != null && regionMap.containsKey(dest.getRegionIdLevel1())){
            dest.setRegionLevel1(regionMap.get(dest.getRegionIdLevel1()));
        }
        if (dest.getRegionIdLevel2() != null && regionMap.containsKey(dest.getRegionIdLevel2())){
            dest.setRegionLevel2(regionMap.get(dest.getRegionIdLevel2()));
        }
        if (dest.getRegionIdLevel3() != null && regionMap.containsKey(dest.getRegionIdLevel3())){
            dest.setRegionLevel3(regionMap.get(dest.getRegionIdLevel3()));
        }
    }

    private void prepareRegion(CustomerResumePreferenceVO dest, Map<Integer, RegionVO> regionMap){
        if (dest == null){
            return;
        }
        if (!CollectionUtils.isEmpty(dest.getInRegionIdLevel2List())){
            List<RegionVO> regionList = new ArrayList<>();
            dest.getInRegionIdLevel2List().stream().forEach(opt -> {
                RegionVO regionVO = regionMap.get(opt);
                if (regionVO != null){
                    regionList.add(regionVO);
                }
            });
            dest.setInRegionLevel2List(regionList);
        }
    }

    private void prepareAttribute(Integer gender, CustomerResumePreferenceVO result, Map<String, AttributeVO> attributeMap){
        if (result == null){
            return;
        }
        if (!CollectionUtils.isEmpty(result.getInDegreeList())){
            List<AttributeValueVO> inDegreeList = new ArrayList<>();
            result.getInDegreeList().stream().forEach(item -> {
                AttributeValueVO attributeVo = getAttributeDisplayValue(attributeMap, AttributeNameEnum.DEGREE.name(), item);
                if (attributeVo != null){
                    inDegreeList.add(attributeVo);
                }
            });
            result.setInDegreeAttributeList(inDegreeList);
        }
        if (!CollectionUtils.isEmpty(result.getInMarriageStatusList())){
            List<AttributeValueVO> arrayList = new ArrayList<>();
            result.getInMarriageStatusList().stream().forEach(item -> {
                AttributeValueVO attributeVo = getAttributeDisplayValue(attributeMap, AttributeNameEnum.MARRIAGE_STATUS.name(), item);
                if (attributeVo != null){
                    arrayList.add(attributeVo);
                }
            });
            result.setInMarriageStatusAttributeList(arrayList);
        }
        result.setEqShapeAttribute(getAttributeDisplayValue(attributeMap, GenderEnum.FEMALE.getValue().equals(gender) ? AttributeNameEnum.SHAPE_GIRL.name()
                : AttributeNameEnum.SHAPE.name(), result.getEqShape()));
        result.setEqChildrenAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.SHAPE.name(), result.getEqChildren()));
        result.setEqWantBabyAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.WANT_BABY.name(), result.getEqChildren()));
        result.setEqSmokeAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.SMOKE.name(), result.getEqChildren()));
        result.setEqDrinkAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.DRINK.name(), result.getEqChildren()));
    }

    private void prepareAttribute(CustomerResumeVO result, Map<String, AttributeVO> attributeMap){
        if (CompareUtils.gtZero(result.getChildren())){
            result.setChildrenAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.CHILDREN.name(), result.getChildren()));
        }
        if (CompareUtils.gtZero(result.getConstellation())){
            result.setConstellationAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.CONSTELLATION.name(), result.getConstellation()));
        }
        if (CompareUtils.gtZero(result.getDegreeHighest())){
            result.setDegreeHighestAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.DEGREE.name(), result.getDegreeHighest()));
        }
        if (CompareUtils.gtZero(result.getExpectWeddingDate())){
            result.setExpectWeddingDateAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.EXPECT_WEDDING_DATE.name(), result.getExpectWeddingDate()));
        }
        if (CompareUtils.gtZero(result.getEthnicity())){
            result.setEthnicityAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.ETHNICITY.name(), result.getEthnicity()));
        }
        if (CompareUtils.gtZero(result.getHouse())){
            result.setHouseAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.HOUSE.name(), result.getHouse()));
        }
        if (CompareUtils.gtZero(result.getMarriageStatus())){
            result.setMarriageStatusAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.MARRIAGE_STATUS.name(), result.getMarriageStatus()));
        }
        if (CompareUtils.gtZero(result.getOccupation())){
            result.setOccupationAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.OCCUPATION.name(), result.getOccupation()));
        }
        if (CompareUtils.gtZero(result.getSalaryMonth())){
            result.setSalaryMonthAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.SALARY_MONTH.name(), result.getSalaryMonth()));
        }
        if (CompareUtils.gtZero(result.getShape())){
            result.setShapeAttribute(getAttributeDisplayValue(attributeMap, GenderEnum.FEMALE.getValue().equals(result.getGender()) ? AttributeNameEnum.SHAPE_GIRL.name() : AttributeNameEnum.SHAPE.name(), result.getShape()));
        }
        if (CompareUtils.gtZero(result.getSmoke())){
            result.setSmokeAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.SMOKE.name(), result.getShape()));
        }
        if (CompareUtils.gtZero(result.getDrink())){
            result.setDrinkAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.DRINK.name(), result.getShape()));
        }
        if (CompareUtils.gtZero(result.getWantBaby())){
            result.setWantBabyAttribute(getAttributeDisplayValue(attributeMap, AttributeNameEnum.WANT_BABY.name(), result.getShape()));
        }

    }

    private static AttributeValueVO getAttributeDisplayValue(Map<String, AttributeVO> attributeMap, String attributeName, Integer valueInt){
        AttributeVO attribute = attributeMap.get(attributeName);
        if (attribute == null){
            return null;
        }
        if (CollectionUtils.isEmpty(attribute.getAttributeValueList())){
            return null;
        }
        return attribute.getAttributeValueList().stream().filter(item -> item.getValueInt().equals(valueInt)).findFirst().orElse(null);
    }

    private Set<Integer> listRegionIdLit(List<CustomerResumeDTO> src){
        if (CollectionUtils.isEmpty(src)){
            return new HashSet<>();
        }
        Set<Integer> result = new HashSet<>(src.size() * 3);
        src.stream().forEach(item ->{
            result.addAll(getRegionIdList(item));
        });
        return result;
    }

    private Set<Integer> getRegionIdList(CustomerResumeDTO src){
        Set<Integer> result = new HashSet<>();
        if (src == null){
            return result;
        }
        if (src.getRegionIdLevel1() != null){
            result.add(src.getRegionIdLevel1());
        }
        if (src.getRegionIdLevel2() != null){
            result.add(src.getRegionIdLevel2());
        }
        if (src.getRegionIdLevel3() != null){
            result.add(src.getRegionIdLevel3());
        }
        if (src.getRegionIdPoi() != null){
            result.add(src.getRegionIdPoi());
        }
        return result;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class CustomerPrepareDTO {
        private CustomerDTO customerDTO;
        private ItemStatisticDTO itemStatisticDTO;
        private CustomerResumeDTO customerResumeDTO;
        private Map<String, String> urlMap;
        private Map<String, AttributeVO> attributeMap;
        private Map<Integer, Integer> contentTotalMap;
        private Map<Integer, RegionVO> regionMap;
        private Map<Long, ItemToggleRelationDTO> fromStarRelation;
    }
}
